package com.cyy.dyeing.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cyy.dyeing.model.Module;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: cyy
 * @Date: 2024/7/25
 */
@Mapper
public interface ModuleMapper extends BaseMapper<Module> {

    @Select("select p.m_id as m_id, p.m_name as p_name, m.m_id as m_pid, m.m_name as m_name," +
            "  (select count(m_id) from t_rm where ro_id=#{roId} and  m_id=m.m_id) as has " +
            "from t_module m join t_module p on m.m_pid = p.m_id " +
            "order by p.m_id, m.m_id;")
    List<Module> getRoleMenuList(@Param("roId") Integer roId);

    @Select("select p.m_id as m_id, p.m_name as p_name, m.m_id as m_pid, m.m_name as m_name, m.m_pc_url as m_pc_url " +
            "    from t_module m " +
            "join t_module p on m.m_pid= p.m_id " +
            "join t_rm rm on rm.m_id = m.m_id " +
            "join t_role r on r.ro_id = rm.ro_id " +
            "join t_ur ur on ur.ro_id = r.ro_id " +
            "join t_user u on u.u_id = ur.u_id " +
            "where u.u_id=#{userId} and u_status=#{code} " +
            "and ro_status=#{code} and p.m_status=#{code} and m.m_status=#{code} " +
            "order by p.m_id, m.m_id")
    List<Module> findModuleListByUid(@Param("userId") String userId, @Param("code") String code);
}
